<?php

error_log("Debugging 0 information: This is a debug message. before sleep");
$configFile = '/etc/fileserver/config.ini'; 
$config = parse_ini_file($configFile, true);
$host = $config['mysql']['host'];  
$username = $config['mysql']['user'];  
$password = $config['mysql']['password'];  
$dbname = $config['mysql']['database']; 
// 创建数据库连接  
$conn = new mysqli($host, $username, $password, $dbname); 
// 检查连接  
if ($conn->connect_error) {  
    die("连接失败: " . $conn->connect_error);  
}  

$file_id = $_GET['file_uuid'];
$sql = "SELECT file_name WHERE file_uuid = {$file_id} FROM users" ;  
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
	$file_path = $row["file_name"];
}	
$path="/var/www/html";

if (strpos($file_path, $path) == false) {  
    $file_path = "/var/www/html/".$file_path;  
}

error_log("Debugging 1 information: This is a debug message. before sleep");
error_log($file_path);
error_log("Debugging 2 information: This is a debug message. before sleep");

// Check if the file exists
while (!file_exists($file_path)) {
    sleep(1);
}

if (file_exists($file_path)) {
    // If the file exists, send it to the client
    header("Content-Disposition: attachment; filename=" . basename($file_path));
    readfile($file_path);
    exit;
}

?>
